package com.easy.activiti.listener;

import com.easy.activiti.ext.TaskEvent;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author zhouchuang
 * 2024-11-05 10:53:16
 */
public class TaskCompleteListener extends AEventHandler {
    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void handle(ActivitiEvent event) {
        System.out.println("===========Task Complete=============");
        TaskEvent taskEvent = dispatchEvent(event);
        getActuator(taskEvent.getProcessDefinitionKey()+"complete").execute(taskEvent);
        //判断是不是拒绝，拒绝需要删除掉流程
        if(taskEvent.getTaskEntity().hasVariable("result") &&
                "0".equals(taskEvent.getTaskEntity().getVariableInstance("result").getValue())){
            taskEvent.reject();
            //并且调用实现类的拒绝方法
            getActuator(taskEvent.getProcessDefinitionKey()+"reject").execute(taskEvent);
        }
    }
}